import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { UploadBizType } from '/@/enums/uploadEnum';
import { listStoreTag } from '../storeTag/storeTag.api';
import { useUserStore } from '/@/store/modules/user';

const userStore = useUserStore()
export const columns: BasicColumn[] = [
  {
    title: '门店ID',
    dataIndex: 'id',
    width: 150,
  },
  {
    title: '图标',
    dataIndex: 'logo',
    width: 80,
    customRender: (record) => {
      return render.renderAvatar(record)
    },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 150,
  },
  {
    title: '员工数',
    dataIndex: 'employeeNumber',
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '0') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'data_use_status'), color)
    },
    width: 60,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '门店名称',
    field: 'name',
    component: 'Input',
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'data_use_status',
      placeholder:'请选择状态',
      stringToNumber:true
    }
  }
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    component: 'Input',
    required: true,
    label: '门店名称',
    componentProps: {
    }
  },
  {
    label: '门店图片',
    field: 'logo',
    component: 'MyImageUpload',
    componentProps: {
      fileMax:1,
      bizType: UploadBizType.GENERAL_IMAGE
    },
  },
  {
    label: '门店地址',
    field: 'address',
    required: false,
    slot: 'selectAddress',
    component: 'Input'
  },
  
  {
    label: '门店电话',
    field: 'phone',
    required: true,
    component: 'Input',
    rules: rules.rule('phone', true),
  },

  {
    label: '门店标签',
    field: 'tags',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      mode: "multiple",
      api: listStoreTag,
      optionFilterProp: "label",
      labelField: 'name',
      valueField: 'id',
      showSearch: true
    },
  },

  {
    label: '营业时间',
    field: 'openTime',
    required: true,
    // defaultValue: JSON.stringify([
    //   {
    //     openWeek: ['1', '2', "3", '4', '5', '6', '7'],
    //     startTime: '06:00',
    //     endTime: '22:00',
    //   }
    // ]),
    component: 'MyStoreOpenTime'
  },

  {
    field: 'status',
    label: '状态',
    required: true,
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      type:'radio',
      dictCode: 'data_use_status',
    },
  },
  {
    field: 'openStatus',
    label: '营业状态',
    required: true,
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      type:'radio',
      dictCode: 'data_use_status',
    },
  },
  {
    label: '门店简介',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      rows: 5,
    },
  }
];


/**
 * 门店设置
 */
export const settingFormSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'bagType',
    label: '外卖包装费类型',
    required: true,
    component: 'JDictSelectTag',
    defaultValue: '0',
    componentProps: {
      type: 'radio',
      dictCode: 'shop_bag_type',
    },
  },
  {
    field: 'bagPrice',
    label: '外卖包装费',
    defaultValue: '0',
    ifShow: ({ values }) => { return values.bagType === '1'},
    component: 'InputNumber',
    componentProps: {
      addonAfter: '元',
      precision: 1
    }
  },

  {
    field: 'storeBagType',
    label: '店内包装费类型',
    required: true,
    component: 'JDictSelectTag',
    defaultValue: '0',
    componentProps: {
      type: 'radio',
      dictCode: 'shop_bag_type',
    },
  },
  {
    field: 'storeBagPrice',
    label: '店内包装费',
    defaultValue: '0',
    ifShow: ({ values }) => { return values.storeBagType === '1'},
    component: 'InputNumber',
    componentProps: {
      addonAfter: '元',
      precision: 1
    }
  },
  {
    field: 'deliveryWays',
    label: '配送方式',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      mode: 'multiple',
      type: 'list',
      dictCode: 'distribution_types',
    }
  },
  
];
